<?php

/*
	info: 用户管理
*/

require dirname(__FILE__).'/include/common.inc.php';


//列表
if ($webglobal['action']=='list')
{
	$tempdefaultpagenum = 20;
	global_CheckPost(
				array(
					array('searchkey','str','','',0,''),
					array('perpage','int','@>0','',0,$tempdefaultpagenum),
			));

	//搜索条件处理
	$tempsearchsql = array();
	$webglobal['searchurl'] = "&action={$webglobal['action']}";	//搜索条件
	if ($webglobal['CPP']['searchkey'] != '')
	{
		$tempsearchfield = array('truename','email','mobile');
		$tempsearchsql[] = $db->BuildSearchSql($webglobal['CPP']['searchkey'], $tempsearchfield);
		$webglobal['searchurl'] .= "&searchkey=".urlencode($webglobal['CPP']['searchkey']);
	}
	//排序设定处理
	$tempshowurl = '';
	if ($webglobal['CPP']['perpage'] != $tempdefaultpagenum)
	{
		$tempshowurl .= "&perpage={$webglobal['CPP']['perpage']}";
	}
	$webglobal['gourl'] = $webglobal['searchurl'].$tempshowurl."&page={$webrequest['page']}";	//整体页面条件
	$webglobal['gourlencode'] = urlencode($webglobal['gourl']);

	$tempsearchsql = empty($tempsearchsql) ? '' : ' WHERE '.implode(' AND ', $tempsearchsql);
	$webglobal['perpage'] = $webglobal['CPP']['perpage'];
	$webglobal['datanum'] = $db->GetNum("SELECT COUNT(*) FROM user{$tempsearchsql}");
	if ($webglobal['datanum'] > 0)
	{
		$webglobal['page'] = global_Page($webglobal['datanum'], $webglobal['perpage'], $webrequest['page'], WEBURLPATH."/{$webserver['curfilename']}.php?{$webglobal['searchurl']}{$tempshowurl}&page=@@");
		$tempstartnum = ($webrequest['page']-1)*$webglobal['perpage'];
		$temporderstr = "uid DESC";
		$query = $db->Query("SELECT * FROM user{$tempsearchsql} ORDER BY {$temporderstr} LIMIT $tempstartnum, {$webglobal['perpage']}");
		$webglobal['dataarray'] = array();
		while ($tempdata = $db->FetchArray($query))
		{
			$tempdata['weddingdate_show'] = !empty($tempdata['weddingdate']) ? global_FormatTime($tempdata['weddingdate'], 'jS F Y') : '';
			$tempdata['addtime_show'] = !empty($tempdata['addtime']) ? global_FormatTime($tempdata['addtime']) : '';
			$webglobal['dataarray'][$tempdata['uid']] = $tempdata;
		}
	}
}
else
{
	global_GoToUrl(WEBURLPATH."/{$webserver['curfilename']}.php?action=list");
}

template_Display($webserver['curfilename']);
